{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#### ICS 104 - Introduction to Programming in Python and C  \n",
    "# Lists, Tuples and Dictionaries\n",
    "## Reading Assignment\n",
    "- Chapter 6 Sections 1, 2, 3 and 4.\n",
    "- Chapter 8 Sections 1 and 2."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Chapters Learning Outcomes\n",
    "### At the end of these two chapters, you will be able to"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "- collect elements using lists\n",
    "- use the for loop for traversing lists\n",
    "- learn common algorithms for processing lists\n",
    "- use lists with functions\n",
    "- build and use a set container\n",
    "- build and use a dictionary container\n",
    "- work with a dictionary for table lookups"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Basic Properties of Lists\n",
    "## Motivation\n",
    "- Assume that you are given 10 values to store in a program for later processing (e.g. finding the largest element).\n",
    "- One way to achieve this is to use 10 variables `value1`, `value2`, ..., `value10`.      "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "- 32\n",
    "- 54\n",
    "- 67.5\n",
    "- 29\n",
    "- 35\n",
    "- 80\n",
    "- 115\n",
    "- 44.5\n",
    "- 100\n",
    "- 65"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- However, such a sequence of variables is not very practical to use. Why?\n",
    "    - Because ...\n",
    "- That is why we can use lists to overcome this difficulty."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Creating Lists\n",
    "- `values = [32, 54, 67.5, 29, 35, 80, 115, 44.5, 100, 65]`\n",
    "    - The square brackets indicate that we are creating a list. \n",
    "    - The items are stored in the order they are provided. "
   ]
  },
  {
   "attachments": {
    "listCreate.jpg": {
     "image/jpeg": "[encoded data, 47076 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "![listCreate.jpg](attachment:listCreate.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Accessing List Elements\n",
    "- A list is a sequence of elements, each of which has an integer position or index\n",
    "- To access a list element, you specify which index you want to use. \n",
    "    - This is done with the subscript operator in the same way that you access individual characters in a **string**."
   ]
  },
  {
   "attachments": {
    "listAccess.jpg": {
     "image/jpeg": "[encoded data, 53100 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "![listAccess.jpg](attachment:listAccess.jpg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "scrolled": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "values = [32, 54, 67.5, 29, 35, 80, 115, 44.5, 100, 65]\n",
    "values[5]=87\n",
    "print(values[5])\n",
    "print(type(values[2]))\n",
    "print(type(values[3]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "center",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Differences between Lists and Strings\n",
    "- There are two differences between **lists** and **strings**\n",
    "    - Lists can hold values of any type, whereas strings are sequences of characters. \n",
    "    - Strings are immutable — you cannot change the characters in the sequence. But lists are mutable."
   ]
  },
  {
   "attachments": {
    "ListSyntax.jpg": {
     "image/jpeg": "[encoded data, 79680 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "![ListSyntax.jpg](attachment:ListSyntax.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- What is the difference between the following?\n",
    "    - `values[4]`\n",
    "    - `values = [4]`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- When accessing a variable in a list, the index of the list must stay within the valid range.\n",
    "    - Otherwise, an **out-of-range** error will result from using an index not in the range."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "values = [32, 54, 67.5, 29, 35, 80, 115, 44.5, 100, 65]\n",
    "values[10]=87"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- One can use the **`len`** function to obtain the length of the list."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "notes"
    }
   },
   "source": [
    "- Use the **`len`** function in the previous code to show its use."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## List Traversal\n",
    "- **List traversal** refers to visiting (and may be processing) each element in the list once."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- There are two ways to traverse a list:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "values = [32, 54, 67.5, 29, 35, 80, 115, 44.5, 100, 65]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "# You have access to index values and elements\n",
    "for i in range(len(values)) :\n",
    " print(i, values[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "# You only have access to elements\n",
    "for element in values :\n",
    " print(element)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## List References\n",
    "- Make sure you see the difference between the:\n",
    "    - List variable:  The named *alias* or pointer to the list\n",
    "    - List contents:  Memory where the values are stored\n",
    "        - which is usually elsewhere"
   ]
  },
  {
   "attachments": {
    "listAccess.jpg": {
     "image/jpeg": "[encoded data, 53100 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "![listAccess.jpg](attachment:listAccess.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- A list variable contains a **reference** to the list contents.  \n",
    "- The **reference** is the location of the list contents (in memory). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- That is why when you assign a list variable into another, both variables refer to the same list\n",
    "    - The second variable is an **alias** for the first because both variables reference the same list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "scores = [10, 9, 7, 4, 5]\n",
    "values = scores"
   ]
  },
  {
   "attachments": {
    "scores.JPG": {
     "image/jpeg": "[encoded data, 27840 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![scores.JPG](attachment:scores.JPG)"
   ]
  },
  {
   "attachments": {
    "scoresAlias.jpg": {
     "image/jpeg": "[encoded data, 38052 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![scoresAlias.jpg](attachment:scoresAlias.jpg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "scores[3] = 10\n",
    "print(values[3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Student Activity\n",
    "- Define a list of integers, `primes`, containing the first five prime numbers.\n",
    "- What does the list `primes` contain after executing the following loop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "## Student Activity\n",
    "# primes\n",
    "for i in range(2) :\n",
    " primes[4 - i] = primes[i]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# List Operations\n",
    "## Appending Elements\n",
    "- If we do not know all the elements of a list, beforehand, we can create an empty list and add elements to the end as needed."
   ]
  },
  {
   "attachments": {
    "AppendingElements.JPG": {
     "image/jpeg": "[encoded data, 66568 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![AppendingElements.JPG](attachment:AppendingElements.JPG)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Inserting Elements\n",
    "- Sometimes the order in which elements are added to a list is important\n",
    "- A new element has to be inserted at a specific position in the list\n",
    "- e.g.,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Emily\", \"Bob\", \"Cari\"]"
   ]
  },
  {
   "attachments": {
    "friends.jpg": {
     "image/jpeg": "[encoded data, 26552 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![friends.jpg](attachment:friends.jpg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Emily\", \"Bob\", \"Cari\"]\n",
    "friends.insert(1, \"Cindy\")\n",
    "print(friends)"
   ]
  },
  {
   "attachments": {
    "friendsAfterInsert.jpg": {
     "image/jpeg": "[encoded data, 49740 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![friendsAfterInsert.jpg](attachment:friendsAfterInsert.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Note that the index at which the new element is to be inserted must be between 0 and the number of elements currently in the list. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Finding an Element\n",
    "- We can determine whether the element is in the list or not"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Emily\", \"Bob\", \"Cari\", \"Emily\"]\n",
    "if \"Cindy\" in friends :\n",
    "    print(\"She's a friend\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- We can, further, determine the index of the element if it is in the list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Emily\", \"Bob\", \"Cari\", \"Emily\"]\n",
    "n = friends.index(\"Emily\")\n",
    "print(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "notes"
    }
   },
   "source": [
    "- You can also try getting the index of something not in the list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Removing an Element\n",
    "- The `pop()` method removes the element at a given position."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Cindy\", \"Emily\", \"Bob\", \"Cari\",\"Bill\"]\n",
    "friends.pop(1)\n",
    "print(friends)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- The `pop()` method without an argument will remove the last element in the list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Cindy\", \"Emily\", \"Bob\", \"Cari\",\"Bill\"]\n",
    "friends.pop()\n",
    "print(friends)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- The element removed from the list is **returned** by the pop() method."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Cindy\", \"Emily\", \"Bob\", \"Cari\",\"Bill\"]\n",
    "print(friends.pop())\n",
    "print(friends)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- The remove method removes an element by ***value*** instead of by ***position***. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "friends = [\"Harry\", \"Cindy\", \"Emily\", \"Bob\", \"Cari\",\"Bill\"]\n",
    "friends.remove(\"Cari\")\n",
    "print(friends)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Note that the value being removed must be in the list or an exception is raised. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Concatenation and Replication\n",
    "- The concatenation of two lists is a new list that contains the elements of the first list, followed by the elements of the second.\n",
    "- This is accomplished using the concatenation operator **`+`**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "myFriends = [\"Fritz\", \"Cindy\"]\n",
    "yourFriends = [\"Lee\", \"Pat\", \"Phuong\"]\n",
    "ourFriends = myFriends + yourFriends\n",
    "print(ourFriends)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- If you want to concatenate the same list multiple times, use the replication operator **`*`**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "# Repeating the same list multiple times\n",
    "monthInQurater = [1, 2, 3] * 4\n",
    "print(monthInQurater)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "# Replication can be used to initialize a list with a fixed value\n",
    "monthlyScores = [0] * 12\n",
    "print(monthlyScores)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Equality Testing\n",
    "- You can use the == operator to compare whether two lists have the same elements, in the same order.\n",
    "- Similarly, you can use the != operator to compare whether two lists are different."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "l1 = [1, 4, 9] == [1, 4, 9]     # Result is\n",
    "l2 = [1, 4, 9 ] == [4, 1, 9]    # Result is\n",
    "l3 = [1, 4, 9] != [1, 4]        # Result is"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "print(\"l1 is\", l1, \", l2 is\", l2, \"and l3 is\", l3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "notes"
    }
   },
   "source": [
    "- The rest of the functions will be introduced in the lab."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Copying Lists\n",
    "- Given a list **`values`**, if we want to make a copy of it, does the following work?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "values = [32, 54, 67.5, 29, 35, 80, 115, 44.5, 100, 65]\n",
    "anotherCopy = values\n",
    "print(values)\n",
    "print(anotherCopy)\n",
    "anotherCopy[2] = -1 \n",
    "print(values)\n",
    "print(anotherCopy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "notes"
    }
   },
   "source": [
    "- Here, in class you can ask and see the response. You can change the code above to print the lists"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- In order to make a copy of the list, use the **`list()`** function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "values = [32, 54, 67.5, 29, 35, 80, 115, 44.5, 100, 65]\n",
    "anotherCopy = list(values)\n",
    "print(values)\n",
    "print(anotherCopy)\n",
    "anotherCopy[2] = -1 \n",
    "print(values)\n",
    "print(anotherCopy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Common List Algorithms\n",
    "- In this section, we will see different tasks that cannot, in general, be performed using a pre-defined library function.\n",
    "- Refer to the textbook for more examples."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "## Filling\n",
    "- Write Python code that will generate a list of squares (0, 1, 4, 9, 16, ..., 100)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "values = []\n",
    "for i in range(11) :\n",
    " values.append(i * i)\n",
    "print(values)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Linear Search\n",
    "- Write Python code to find the index of the first value greater than 100 in a list of numbers. Your code should display `Not Found` if such element does not exist."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "values = [-1, 5, 19, 22, 33, 106] * 7\n",
    "limit = 100\n",
    "pos = 0\n",
    "found = False\n",
    "while pos < len(values) and not found :\n",
    "    if values[pos] > limit :\n",
    "        found = True\n",
    "    else :\n",
    "        pos = pos + 1 \n",
    "            \n",
    "if found :\n",
    "    print(\"Found at position:\", pos)\n",
    "else :\n",
    "    print(\"Not found\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Swapping Elements\n",
    "- Given a list of values, `values`, swap the first element with the last element\n",
    "- Does the following code work?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "values = [-1, 5, 19, 22, 33, 106]\n",
    "values[0] = values[len(values)-1]\n",
    "values[len(values)-1] = values[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "print(values)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- What we need to do is store the first value **somewhere** before assigning it to the other element."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "values = [-1, 5, 19, 22, 33, 106]\n",
    "temp = values[0]\n",
    "values[0] = values[len(values)-1]\n",
    "values[len(values)-1] = temp\n",
    "print(values)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Using Lists with Functions\n",
    "- A function can accept a list as an argument.\n",
    "- The following function multiplies all elements of a list by a given factor:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "def multiply(values, factor) :\n",
    "    for i in range(len(values)) :\n",
    "        values[i] = values[i] * factor\n",
    "scores = [32, 54, 67.5, 29, 35]        \n",
    "multiply (scores, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "# Do you think that the values of the list scores will change?\n",
    "print(scores)    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- The answer is yes. The reason is that `values` has a copy of the reference to the `scores` list."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Let us see exactly what happened."
   ]
  },
  {
   "attachments": {
    "listAsArgument0.jpg": {
     "image/jpeg": "[encoded data, 54080 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "![listAsArgument0.jpg](attachment:listAsArgument0.jpg)"
   ]
  },
  {
   "attachments": {
    "listAsArgument1.jpg": {
     "image/jpeg": "[encoded data, 54644 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![listAsArgument1.jpg](attachment:listAsArgument1.jpg)"
   ]
  },
  {
   "attachments": {
    "listAsArgument2.jpg": {
     "image/jpeg": "[encoded data, 81080 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![listAsArgument2.jpg](attachment:listAsArgument2.jpg)"
   ]
  },
  {
   "attachments": {
    "listAsArgument3.jpg": {
     "image/jpeg": "[encoded data, 34260 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "![listAsArgument3.jpg](attachment:listAsArgument3.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Returning Lists from Functions\n",
    "- Create and build the list inside the function and then return it.\n",
    "- The following example function **`squares`** returns a list of squares from $0^2$ up to $(n–1)^2$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "def squares(n) :\n",
    "    result = []\n",
    "    for i in range(n) :\n",
    "        result.append(i * i)\n",
    "    return result\n",
    "myList = squares(8)\n",
    "print(myList)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Tuples\n",
    "- A tuple is similar to a list, but once created, its contents cannot be modified.\n",
    "    - i.e., a tuple is an immutable version of a list."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- A tuple is created by specifying its contents as a comma-separated sequence. \n",
    "- You can either enclose the sequence in parentheses or omit them."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "triple1 = (5, 10, 15)\n",
    "triple2 = 5, 10, 15\n",
    "print(triple1==triple2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- Tuples are commonly used to return **multiple values** from functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "# Function definition\n",
    "def readDate() :\n",
    "    print(\"Enter a date:\")\n",
    "    month = int(input(\" month: \"))\n",
    "    day = int(input(\" day: \"))\n",
    "    year = int(input(\" year: \"))\n",
    "    return (month, day, year) # Returns a tuple.\n",
    "\n",
    "# Function call: assign entire value to a tuple\n",
    "date = readDate()\n",
    "print(date)\n",
    "\n",
    "# Function call: use tuple assignment: \n",
    "(month, day, year)  = readDate() \n",
    "print(day, \"/\", month,\"/\", year)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Sets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "- A set is a container that stores a collection of **unique** values.\n",
    "    - Therefore, elements cannot be repeated in a set, *unlike* a list."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Unlike a list, the elements or members of the set are not stored in any particular order and cannot be accessed by position."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Operations are the same as the operations performed on sets in mathematics."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Because sets do not need to maintain a particular order, set operations are much faster than the equivalent list operations."
   ]
  },
  {
   "attachments": {
    "Flags.jpg": {
     "image/jpeg": "[encoded data, 37596 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Examples of Sets\n",
    "- Following are three examples of sets of color, the colors of the British, Canadian and Italian flags.\n",
    "![Flags.jpg](attachment:Flags.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- As you can see, \n",
    "    - the order does not matter, and\n",
    "    - no color is repeated."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Creating Sets\n",
    "- To create an empty set,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "## Creating Empty Sets\n",
    "empty1 = {}   # This notation exists for historical reasons\n",
    "empty2 = set() # Preferred way of creating empty sets\n",
    "print(empty1)\n",
    "print(empty2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- To create a set with initial values, you can either specify it the way we represent sets in mathematics, using the curly braces **`{}`**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "cast = { \"Luigi\", \"Gumbys\", \"Spiny\" }\n",
    "print(cast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Or, you can convert an already existing **list** into a set. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "names = [\"Luigi\", \"Gumbys\", \"Spiny\", \"Spiny\"]\n",
    "cast = set(names)\n",
    "print(cast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Adding and Removing Elements\n",
    "- Like lists, sets are mutable collections, so you can add and remove elements."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- New elements can be added using the `add` method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "cast = set([\"Luigi\", \"Gumbys\", \"Spiny\"]) \n",
    "cast.add(\"Arthur\") \n",
    "print(cast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- What do you think will happen when you try to add an element that is already in the set?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- Elements can be removed using either the `discard` method or the `remove` method.\n",
    "- Both methods remove individual elements from a set, if those elements are in the set."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- If the element to be removed is not in the set\n",
    "    - Using `discard` does not have any effect on the set or the program.\n",
    "    - Using `remove` raises an exception. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "cast = set([\"Luigi\", \"Gumbys\", \"Spiny\"]) \n",
    "cast.discard(\"Spiny\")\n",
    "print(cast)\n",
    "cast.discard(\"Spiny\")\n",
    "print(cast)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "cast = set([\"Luigi\", \"Gumbys\", \"Spiny\"]) \n",
    "cast.remove(\"Spiny\")\n",
    "print(cast)\n",
    "cast.remove(\"Spiny\")\n",
    "print(cast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Dictionaries"
   ]
  },
  {
   "attachments": {
    "Dictioanry.JPG": {
     "image/jpeg": "[encoded data, 27804 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "- A dictionary is a container that keeps associations between **keys** and **values**. \n",
    "    - Every key in the dictionary has an associated value.  \n",
    "  \n",
    "![Dictioanry.JPG](attachment:Dictioanry.JPG)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- Keys are unique, but a value may be associated with several keys. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "favoriteColors = { \"Romeo\": \"Green\", \"Adam\": \"Red\", \"John\": \"Blue\", \"Sam\": \"Red\" }\n",
    "print(favoriteColors)"
   ]
  },
  {
   "attachments": {
    "SetsAndDictionaries.JPG": {
     "image/jpeg": "[encoded data, 82304 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- The dictionary structure is also known as a **map** because it maps a unique key to a value.  \n",
    "\n",
    "![SetsAndDictionaries.JPG](attachment:SetsAndDictionaries.JPG)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Creating Dictionaries\n",
    "- A dictionary is created where each key:value pair is separated by a colon.\n",
    "- The collection of key:value pairs are enclosed in braces.\n",
    "- Note that when the braces contain key:value pairs, they denote a dictionary, not a set. \n",
    "- The only ambiguous case is an empty {}. By convention, it denotes an empty dictionary, not an empty set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "center",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "print(contacts)"
   ]
  },
  {
   "attachments": {
    "contacts.JPG": {
     "image/jpeg": "[encoded data, 21192 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "![contacts.JPG](attachment:contacts.JPG)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- You can create a duplicate copy of a dictionary using the `dict` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "oldContacts = dict(contacts)\n",
    "print(oldContacts)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Accessing Dictionary Values\n",
    "- The subscript operator []  is used to return the value associated with a key."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "print(\"Bob's number is\", contacts[\"Bob\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Are the **key:value** pairs of the dictionary ordered?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- The answer is No. You cannot access the items by index or position. \n",
    "    - A **value** can only be accessed using its associated **key**."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- Note that the key supplied to the subscript operator must be a valid key in the dictionary, otherwise a `KeyError` exception will be raised."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "if \"John\" in contacts :\n",
    "    print(\"John's number is\", contacts[\"John\"])\n",
    "else :\n",
    "    print(\"John is not in my contact list.\")\n",
    "if \"Sarah\" not in contacts :\n",
    "    print(\"Sarah is not in my contact list.\")\n",
    "else :\n",
    "    print(\"Sarah's number is\", contacts[\"Sarah\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- Instead of using an `if` statement to make sure that a contact exists before you get its associated value, you can use the `get` method and supply it with a *default value* to return, if the key was not in the dictionary."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "myContact = \"Fred\"\n",
    "myNumber = contacts.get(myContact, 411)\n",
    "print(\"The phone number of \" + myContact + \" is \" + str(myNumber)) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Adding and Modifying Items in a Dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "contacts[\"John\"] = 2034847 # Adding a new contact\n",
    "print(contacts)\n",
    "contacts[\"John\"] = 2037663 # Modifying the value of a contact\n",
    "print(contacts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "favoriteColors = {}                # In case we do not know the elements of the dictionary beforehand\n",
    "favoriteColors[\"Juliet\"] = \"Blue\"  # Add a key:value pair to the dictionary\n",
    "favoriteColors[\"Adam\"] = \"Red\"     # Add a key:value pair to the dictionary\n",
    "favoriteColors[\"Eve\"] = \"Blue\"     # Add a key:value pair to the dictionary\n",
    "favoriteColors[\"Romeo\"] = \"Green\"  # Add a key:value pair to the dictionary\n",
    "print(favoriteColors)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Removing a key from a Dictionary\n",
    "- Call the `pop` method with the key as the argument. \n",
    "- `pop` returns the value of the removed key.\n",
    "- A `KeyError` exception is raised if the key to be removed is not in the dictionary."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "fredsNumber = contacts.pop(\"Fred\")\n",
    "print(contacts)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Traversing a Dictionary\n",
    "- To access the value associated with a key in the body of the loop, you can use the loop variable with the subscript operator. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "print(\"My Contacts:\")\n",
    "for key in contacts :\n",
    "    print(\"%-10s %d\" % (key, contacts[key] ))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- To iterate through the keys in sorted order, you can use the `sorted` function as part of the for loop: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "print(\"My Contacts:\")\n",
    "for key in sorted(contacts) :\n",
    "    print(\"%-10s %d\" % (key, contacts[key] ))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "- You can also iterate over the values of the items, instead of the keys, using the `values` method. \n",
    "- This can be useful for creating a list that contains all of the phone numbers in our dictionary:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "contacts = { \"Fred\": 7235591, \"Mary\": 3841212, \n",
    "            \"Bob\": 3841212, \"Sarah\": 2213278 }\n",
    "phoneNumbers = [] # Create an empty list.\n",
    "for number in contacts.values()  :\n",
    "    phoneNumbers.append(number)\n",
    "print(phoneNumbers)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "- This can also be achieved through the `list` function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cell_style": "split",
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "samePhoneNumbers = list(contacts.values())\n",
    "print(samePhoneNumbers) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Summary\n",
    "- Use lists for collecting values.\n",
    "- Know and use the built-in operations for lists.\n",
    "- Know and use common list algorithms.\n",
    "- Implement functions that process lists.\n",
    "- Understand the concept of a set and some operations on it.\n",
    "- Work with Python dictionaries."
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
